package com.yscp.ysdemo.common;



import com.yscp.ysdemo.constant.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class sensitiveWordsRequestWrapper extends HttpServletRequestWrapper {

    private static WordsFilter wordsFilter = new WordsFilter();
    public sensitiveWordsRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getParameter(String name) {
        String value = super.getParameter(name);
        if(value != null && !Constants.PARAMS_PASE.contains(name))
            value = wordsFilter.filterWord(value);
        return value;
    }

    @Override
    public String[] getParameterValues(String name) {
        String[] arr = super.getParameterValues(name);
        if (arr != null) {
            for (int i = 0; i < arr.length; i++) {
                if(arr[i] != null && !Constants.PARAMS_PASE.contains(name))
                    arr[i] = wordsFilter.filterWord(arr[i]);
            }
        }
        return arr;
    }
}
